package com;

import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.datasettransform.service.IGroovyHandler;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 建议在idea写好复制整个类到此处，位置report-core/src/test/java/com/DemoGroovyHandler.java
 */
public class DemoGroovyHandler implements IGroovyHandler {

    @Override
    public List<JSONObject> transform(List<JSONObject> data) throws ParseException {
        List<JSONObject> result = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("locate", data.get(i).getString("locate"));
            jsonObject.put("level", data.get(i).getString("level"));
            jsonObject.put("context", data.get(i).getString("context"));
            jsonObject.put("time", data.get(i).getString("time"));
            jsonObject.put("locate", data.get(i).getString("locate"));
            String state = "";
            switch (data.get(i).getString("state")) {
                case "1":
                    state = "未处理";
                    break;
                case "2":
                    state = "处理中";
                    break;
                case "3":
                    state = "已完结";
                    break;
                case "4":
                    state = "已忽略";
                    break;
            }
            jsonObject.put("state", state);
            result.add(jsonObject);
        }
        return result;
    }
}